z<template>
  <div class="SalesRecord">
    <div class="salesRecordContent">
      <TableList :tableData="tableData" :titleList="titleList" :linklist="linklist" :btnState="btnState"
        :limit="limit" />
    </div>
    <Paging :total="total" @getPage="getPage" @getLimit="getLimit" />
    <router-view />
  </div>
</template>

<script>
  import TableList from "../../components/List.vue";
  import Paging from '../../components/Paging.vue';
  import { salesRecordList } from '../../http/apis/goodsApi/salesRecord.js'
  import { mapState, mapMutations, mapActions } from 'vuex'
  // 时间戳的转换
  import { timeFormat } from "../../utils/utils";
  export default {
    components: {
      TableList,
      Paging,
    },

    data() {
      return {
        btnState:3,
        // 表格数据
        tableData: [],
        // 默认每页总数
        limit: 3,
        // 当前页数
        page: 1,
      }
    },
    computed: {
      ...mapState('goodsStore', ['type','linklist', 'titleList', 'state', 'total'])
    },
    methods: {
      ...mapMutations('goodsStore', ['SalesRecordlist']),
      ...mapActions('goodsStore', ['GetCounts']),
      // 翻页
      getPage(val) {
        this.page = val;
        this.dataShow();
      },
      // 修改每页显示长度
      getLimit(val) {
        this.limit = val;
        this.dataShow();
      },
      // 渲染数据转格式
      showDataType(datas) {
        let listArr = datas.filter((item) => {
          item.order_goods_date = timeFormat(item.order_goods_date)
          return item;
        });
        return listArr;
      },
      // 页面渲染
      dataShow() {
        salesRecordList({
          currentPage: this.page,
          pageSize: this.limit,
        })
          .then((res) => {
            console.log('销售列表渲染成功请求:', res);
            if (res.data.code == '200') {
              this.tableData = this.showDataType(res.data.data)
            }
          })
          .catch((err) => {
            console.log('请求失败', err)
          });
      },
    },
    created() {
      this.SalesRecordlist();
      this.GetCounts({ database: this.type })
      this.dataShow()
      console.log(this.btnState)
    },
  };
</script>

<style>
</style>